//
//  ANProductDetailCellFrame.m
//  Ants
//
//  Created by ZHM on 16/3/29.
//  Copyright © 2016年 ZHM. All rights reserved.
//

#import "ANProductDetailCellFrame.h"

@implementation ANProductDetailCellFrame

- (void)setProduct:(ANBDProduct *)product {
    _product = product;
    
    CGFloat nameX = ANCellMargin;
    CGFloat nameY = 5;
    CGFloat nameW = ANscreenW - ANCellMargin * 2;
    CGSize nameSize = [_product.title sizeOfTextWithMaxSize:CGSizeMake(nameW, MAXFLOAT) font:ANNameLabelSize];
    _nameLabelFrame = (CGRect){{nameX,nameY},nameSize};
    
    CGFloat detailX = nameX;
    CGFloat detailY = CGRectGetMaxY(_nameLabelFrame) + ANCellMargin;
    CGFloat detailW = ANscreenW - ANCellMargin * 2;
    CGSize detailSize = [_product.intro sizeOfTextWithMaxSize:CGSizeMake(detailW, MAXFLOAT) font:ANDetailLabelSize];
    _detailLabel = (CGRect){{detailX,detailY},detailSize};
    
    NSDecimalNumber *price = product.price;
    NSDecimalNumber *originalPrice = product.originalPrice;
    _priceLabelText = [NSString stringWithFormat:@"￥%@", price];
    _originPriceLabelText = [NSString stringWithFormat:@"原价￥%@", originalPrice];
    
    
    CGFloat priceLabelX = nameX;
    CGFloat priceLabelY = CGRectGetMaxY(_detailLabel) + ANCellMargin;;
    NSDictionary *attrib = @{NSFontAttributeName:ANpriceLabelSize};
    CGSize priceLabelSize = [_priceLabelText sizeWithAttributes:attrib];
    _priceLabel = (CGRect){{priceLabelX,priceLabelY},priceLabelSize};
    
    CGFloat originPriceLabelX = nameX;
    CGFloat originPriceLabelY = CGRectGetMaxY(_priceLabel) + ANCellMargin;;
    NSDictionary *originPriceLabelattrib = @{NSFontAttributeName:ANoriginPriceLabelSize};
    CGSize originPriceLabelSize = [_originPriceLabelText sizeWithAttributes:originPriceLabelattrib];
    _originPriceLabel = (CGRect){{originPriceLabelX,originPriceLabelY},originPriceLabelSize};
    
    NSString *serversText = @"";
    for (int i = 0; i < _product.services.count; i++) {
        if (i == 0) {
            serversText = [serversText stringByAppendingString:[NSString stringWithFormat:@"%@",_product.services[i]]];
        } else {
            serversText = [serversText stringByAppendingString:[NSString stringWithFormat:@"-%@",_product.services[i]]];
        }
    }
    _serversText = [NSString stringWithFormat:@"服务: %@",serversText];
    
    CGFloat serverX = nameX;
    CGFloat serverY = CGRectGetMaxY(_originPriceLabel) + ANCellMargin;
    CGFloat serverW = ANscreenW - ANCellMargin * 2;
    CGSize serverSize = [_serversText sizeOfTextWithMaxSize:CGSizeMake(serverW, MAXFLOAT) font:ANDetailLabelSize];
    _serverLabel = (CGRect){{serverX,serverY},serverSize};
    
    _cellHeight = CGRectGetMaxY(_serverLabel) + ANCellMargin;
}

@end
